<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <link href="../../css/style.css" rel="stylesheet" type="text/css"/>
    <style type="text/css">
        td{word-break: break-all; word-wrap:break-word;}
    </style>
    <title>销售单列表</title>
</head>
<body>
<script src="../../js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="../../js/JPageController.js" type="text/javascript"></script>
<script src="../../js/comm.js" type="text/javascript"></script>
<script src="../../js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script src="../../js/util.js" type="text/javascript"></script>
<script src="../../js/JBusinessCom.js" type="text/javascript"></script>
<script src="../../js/jquery.autocomplete.min.js" type="text/javascript"></script>
         <div id="loading"></div>

    <table style="min-width: 882px;" width="100%" border="0" height="100%" cellspacing="0" cellpadding="0">
        <tr>
            <td valign="top" bgcolor="#e6e6e8" class="main">

          <table width="100%" border="0" cellspacing="0" cellpadding="0" height="500">
              <tr>
            <td valign="top">
            <div class="buttonArea">

            <input id="WriteBack" name="WriteBack" type="hidden" value="" />
                 <div class="right">
                        <span class="fl">
                        <span id="simpleSearch">
                            <input class="inputText fl" id="SearchSaleKey" name="SearchSaleKey" placeholder="请输入模糊关键字" size="30" type="text" value="" />
                            <a class="button" onclick="reload()" id="search">搜索</a></span>
                        <a class="button" id="aAdvanced">高级搜索</a></span>
                    </div>
                    <span id="message" style="color:red;font-size: 18px"></span>
                    <div class="searchAdvanced" style="display: none;" id="highSearch">
                        <div>
                            <input id="Advanced" name="Advanced" type="hidden" value="" />
                            <span class="title">创建日期</span>
                            <input class="inputText" id="SearchCreateStartDate" name="SearchCreateStartDate" onClick="WdatePicker()" readonly="true" size="10" type="text" value="" />
                            <span>&nbsp;&nbsp;~&nbsp;&nbsp;</span>
                            <input class="inputText" id="SearchCreateEndDate" name="SearchCreateEndDate" onClick="WdatePicker()" readonly="true" size="10" type="text" value="" />
                        </div>
                         <div>
                            <span class="title">经手人</span><input class="inputText" id="SearchUser" size="8" name="SearchUser" type="text" value="" />
                        </div>
                        <div>
                            <span class="title">业务日期</span>  <input class="inputText" id="SearchStartDate" name="SearchStartDate" onClick="WdatePicker()" readonly="true" size="10" type="text" value="" /> <span>&nbsp;&nbsp;~&nbsp;&nbsp;</span>
                            <input class="inputText" id="SearchEndDate" name="SearchEndDate" onClick="WdatePicker()" readonly="true" size="10" type="text" value="" />
                        </div>
                        <div>
                            <span class="title">制单人</span><input class="inputText" id="SearchCreateUser" size="8" name="SearchCreateUser" type="text" value="" />
                        </div>
                        <div>
                            <span class="title"><a class="button" onclick="reload()" id="searchAdvance">搜索</a></span>
                        </div>
                     </div>

        </div>
                <!-- buttonArea -->
                <div class="clear height10"></div>
                 <div class="shadowBoxWhite tableDiv">
             <input type="hidden" id="url" />
             <div id="dvOrders"></div>

            <table width="100%" border="0" cellspacing="1" cellpadding="5" id="resultTable"></table>
           </div>

            </td>
        </tr>
    </table>
</td>
        </tr>
    </table>



</body>
</html>
<script type="text/javascript">//<![CDATA[
function _MvcPager_Keydown(e){var _kc,_pib;if(window.event){_kc=e.keyCode;_pib=e.srcElement;}else if(e.which){_kc=e.which;_pib=e.target;}var validKey=(_kc==8||_kc==46||_kc==37||_kc==39||(_kc>=48&&_kc<=57)||(_kc>=96&&_kc<=105));if(!validKey){if(_kc==13){ _MvcPager_GoToPage(_pib,2);}if(e.preventDefault){e.preventDefault();}else{event.returnValue=false;}}}function _MvcPager_GoToPage(_pib,_mp){var pageIndex;if(_pib.tagName=="SELECT"){pageIndex=_pib.options[_pib.selectedIndex].value;}else{pageIndex=_pib.value;var r=new RegExp("^\\s*(\\d+)\\s*$");if(!r.test(pageIndex)){alert("页索引无效");return;}else if(RegExp.$1<1||RegExp.$1>_mp){alert("页索引超出范围");return;}}var _hl=document.getElementById(_pib.id+'link').childNodes[0];var _lh=_hl.href;_hl.href=_lh.replace('*_MvcPager_PageIndex_*',pageIndex);if(_hl.click){_hl.click();}else{var evt=document.createEvent('MouseEvents');evt.initEvent('click',true,true);_hl.dispatchEvent(evt);}_hl.href=_lh;}
//]]>
        //初始化排序图标
    var sortorder = "";
    var usortname = "";
    $(document).ready(function () {

         //初始化排序图标
        sortorder = request.QueryString("sortorder");
        usortname = request.QueryString("sortname");
        if (usortname == '' || null == usortname) {
            usortname = "CreateDate";
            sortorder = "desc";
        }
        $("#url").val("Sale/SelectSaleNo.html?sortname="+usortname+"&sortorder="+sortorder+"");
        requestJson["SortName"] = usortname;
        requestJson["SortOrder"] = sortorder;
    });

        //供排序使用
    function setSortView(){
        //初始化排序图标
        if (sortorder == 'asc')
            $('#' + usortname).addClass("Oup");
        else
            $('#' + usortname).addClass("Odown");
    }
</script>

<script type="text/javascript">
    $(document).ready(function () {
        //打印
        var isPrint = requestUrlPara("IsPrint");
        var printSaleId = requestUrlPara("SaleId");
        if (isPrint == 1) {
            OpenPrint('/Sale/Print?SaleId=' + printSaleId);
        }
        var isToList = requestUrlPara("IsToList");
        if (isToList == 1) {
            parent.CloseTabByTitle('新增销售');
            parent.CloseTabByTitle('复制新增销售单');
            parent.CloseTabByTitle('借出转销售')
        }
        var employeeheader = { EmployeeCode: "帐号", EmployeeName: "经手人" };
        $("#SearchUser").autoComplete({
            header: employeeheader,
            url: "/shared/queryemployee",
            width: 220,
            selected: function (o) {
                $("#SearchUser").val(o.EmployeeName);
            }
        });
    });

    // 重新加载数据
    function reload() {
        requestJson["Page"] = 1;
        requestJson["rp"] = 10
        querySaleList();
//        MVCPage(getPageParams());
    }


    $(function () {
        //初始化查询方式
        var advanced = request.QueryString("advanced");
        if (advanced == "1") {
            $("#Advanced").val(1);
            $("#simpleSearch").hide();
            $(".searchAdvanced").show();
            //$("#aAdvanced").text("简单搜索");
            $("#aAdvanced").addClass("searchAdvancedS");
        } else {
            $("#Advanced").val(0);
            $("#simpleSearch").show();
            $(".searchAdvanced").hide();
            //$("#aAdvanced").text("高级搜索");
            $("#aAdvanced").removeClass("searchAdvancedS");
        }
    });

        //高级查询按钮
        $("#aAdvanced").click(function () {
            $("#highSearch input[name != 'Advanced']").val("");
            $("#SearchSaleKey").val("");
            if ($("#Advanced").val() == "0") {
                $("#Advanced").val(1);
                $("#simpleSearch").show();
                //$("#aAdvanced").text("简单搜索")
                $("#aAdvanced").addClass("searchAdvancedS");
            } else {
                $("#Advanced").val(0);
                $("#simpleSearch").hide();
                //$("#aAdvanced").text("高级搜索");
                $("#aAdvanced").removeClass("searchAdvancedS");
            }
            $(".searchAdvanced").slideToggle("slow");

        });

    //得到高级查询的参数
    function getHighQueryParam(){
        var searchCreateStartDate = $("#SearchCreateStartDate").val();
        var searchCreateEndDate = $("#SearchCreateEndDate").val();
        var searchUser = $("#SearchUser").val().trim();
        var searchStartDate = $("#SearchStartDate").val();
        var searchEndDate = $("#SearchEndDate").val();
        var searchCreateUser = $("#SearchCreateUser").val().trim();
             requestJson["SearchCreateStartDate"] = searchCreateStartDate;
             requestJson["SearchCreateEndDate"] = searchCreateEndDate;
             requestJson["SearchClient"] = "";
             requestJson["SearchUser"] = searchUser;
             requestJson["SearchStartDate"] = searchStartDate;
             requestJson["SearchEndDate"] = searchEndDate;
             requestJson["SearchCreateUser"] = searchCreateUser;
             requestJson["WarehouseName"] = "";
    }

    $(function () {
        $("#chkZF").click(function () { $("#WriteBack").val($(this).attr("checked") ? "0" : "1"); })
    });
</script>
<script type="text/javascript">
    var IsOpenSaleTaxRate;
         var requestJson = {
                "Page": 1,
                "rp": 10
            };
 //查询销售历史列表
    function querySaleList() {
        var sysconf = getSysConfig();
        sysconf = eval("(" + sysconf + ")");
        IsOpenSaleTaxRate = sysconf['IsOpenSaleTaxRate'];
        if(IsOpenSaleTaxRate == undefined){
            IsOpenSaleTaxRate = 0
        }
        $("#resultTable").html("");
        try {
                requestJson["WriteBack"] = '0';
                getHighQueryParam();
                requestJson["SearchSaleKey"] = $("#SearchSaleKey").val().trim();
            var recordList = parent.sale_bi.querySaleList(JSON.stringify(requestJson));
            recordList = eval("(" + recordList + ")");

            var tableResult = creatHeadHtml();
            var deleteTableResult = [];
            var curPage = recordList["CurPage"];
            var pageCount = recordList["PageCount"];
            var recordCount = recordList["RecordCount"];
            var isBackGoods = recordList["IsBackGoods"];
            var index = 0;
            var unDelIndex = 0;
            if(recordList["Data"].length > 0){
                for(var i = 0; i < recordList["Data"].length; i++){
                    var record = recordList["Data"][i];
                    if( recordList["Data"][i]["WriteBack"] == '1'){
//                        deleteTableResult = deleteTableResult + createDataRow(record,i,curPage)
                        deleteTableResult[index] = record;
                        index++;
                    }else{
                        tableResult = tableResult + createDataRow(record,unDelIndex,curPage,isBackGoods)
                        unDelIndex++;
                    }
                }

                for(var i = 0; i < deleteTableResult.length;i++){
                    tableResult = tableResult + createDataRow(deleteTableResult[i],i,curPage)
                }
                tableResult = tableResult +deleteTableResult+ creatLastRow(curPage,pageCount,recordCount);
            }else{
                tableResult = tableResult +noQueryData();
            }
            $("#resultTable").html(tableResult)
            var record = recordList[recordList.length - 1];

//            alert(recordList.length);
            //$("#saleNum").html(record['SaleAmt']);
        } catch (e) {
            alert("exception="+e)
        }
    }

    //没有查到数据时
    function noQueryData(){
        var result = ' <div class="clear height10"></div>'+
           '<div class="shadowBoxWhite">'+
                '<table align="center">'+
                    '<tr>'+
                        '<td align="center" style="background-color: #FFFFFF">'+
                            '<p>&nbsp;</p>'+
                            '<p>'+
                              ' <img src="../../images/nodata_sale.png" />'+
                            '</p>'+
                            '<p class="fontNodata">'+
                                '当前还没有任何销售单<br />'+
                            '</p>'+
                            '<p>&nbsp;</p>'+
                        '</td>'+
                    '</tr>'+
                '</table>'+
        '</div>'
        return result;

    }
  //创建查询列表的最后一行
    function creatLastRow(curPage,pageCount,recordCount){
        var oriStr =
                  '<tr id="lastLine">'
                  if(IsOpenSaleTaxRate == "1"){
                     oriStr = oriStr + '    <td colspan="11" align="left" valign="middle" bgcolor="#FFFFFF">'
                  }else{
                      oriStr = oriStr + '    <td colspan="10" align="left" valign="middle" bgcolor="#FFFFFF">'
                  }

                  oriStr = oriStr + '        {pager_context}'+
                  '    </td>'+
                  '</tr>';
        var oriStr = oriStr.replace("{pager_context}",creatPageController(curPage,pageCount,recordCount,"querySaleList();",6));
        return oriStr;
    }

    $(window).load(function () {
        querySaleList();
        setSortView();
    });

     // 创建表头html
    function creatHeadHtml(){
        var oriStr =
                 '<tr>'+
                    '<th width="20" align="center" style="display: none;">'+
                        '<input type="checkbox" onclick="SelAll(this);" name="selectall" /></th>'+
                    '<th width="30" align="center">序号</th>'+
                    '<th align="center" width="80">'+
                        '<a data-ajax="true" data-ajax-mode="replace" data-ajax-update="#dvOrders" href="javascript:;" class="Ohead" id="SaleDate" onclick="Sort1(\'SaleDate\',this,\'选择销售单\')">业务日期</a>'+
                    '</th>'+
                    '<th align="center" width="120">'+
                        '<a data-ajax="true" data-ajax-mode="replace" data-ajax-update="#dvOrders" href="javascript:;" class="Ohead" id="SaleNo" onclick="Sort1(\'SaleNo\',this,\'选择销售单\')">单据编号</a>'+
                    '</th>'+
                    '<th width="100" align="center">客户名称</th>'+
                    '<th align="left">销售商品</th>';
                      if(IsOpenSaleTaxRate == '1'){
                           oriStr = oriStr +'<th width="80" align="center" name="IsOpenSaleTaxRate_1">税后金额(元)</th>'
                       }else{
                          oriStr = oriStr +'<th width="80" align="center" name="IsOpenSaleTaxRate_1">应退金额(元)</th>'
                      }
                   oriStr = oriStr + '<th width="80" align="center">已收金额(元)</th>'+

                    '<th width="80" align="center">结算方式</th>'+
                    '<th width="80" align="center">出库仓库</th>'+
                    '<th width="50" align="center">操作</th>'+
                '</tr>'
        return oriStr;
    }

/*--子窗口排序排序--*/
function Sort1(sortname, obj, titleName) {
    var sortorder = request.QueryString("sortorder");
    var usortname = request.QueryString("sortname");
    var url = $("#url").val();
    if (url.indexOf('?') > -1) {
        if (usortname == sortname) {
            if (sortorder == 'asc')
                url = url.replace('=asc', '=desc');
            else
                url = url.replace('=desc', '=asc');
        }
        else
            url = url.substring(0, url.indexOf("?") + 1) + "sortname=" + sortname + "&sortorder=asc";
    } else
        url += "?sortname=" + sortname + "&sortorder=" + sortorder + "";
        parent.$('#openIframe')[0].src = url;
        parent.$('#openFrameDiv').dialog('open');
}


     //创建数据行
    function createDataRow(record,index,page,isBackGoods){
        var saleId = record['SaleId'];
//        var productId = record["ProductId"].split("、");
        var saleDate = record['SaleDate'].substring(0,10);
        var saleNo = record['SaleNo'];
        var clientName = record['ClientName'];
        var accountSimpleName = record['AccountSimpleName'];
//        var afterTaxAmt = record['AfterTaxAmt'];
        var afterTaxAmt = record['FAReceAmt'];
        if(afterTaxAmt != ""){
            afterTaxAmt = getSystemDecimal(afterTaxAmt);
        }
        var warehouseSimpleName = record['WarehouseName'];
        var warehouseName = record['WarehouseName'];
        var receAmt = getSystemDecimal(record['ReceAmt']);
        var productName = record['ProductName'];
        var writeBack = record["WriteBack"];
        var clientId = record["ClientId"];
        var warehouseId = record["WareHouseId"];
        var otherFee = record["OtherFee"];
        var accountId = record["AccountId"];
        var oriStr = "";

              if(writeBack == '0'){
                  if($.inArray(saleId,isBackGoods)!=-1){
                        oriStr = oriStr + '<tr> <td align="center"  bgcolor="#FFFFFF">'+
                        '<div class="returnGoodsIcon"></div>'
                  }else{
                      oriStr = oriStr +  '<tr> <td bgcolor="#FFFFFF" align="center">'+ (((page-1)*10)+(index+1))
                  }
              }else{
                  oriStr = oriStr + '<tr  class="cancel"> <td align="center"  bgcolor="#FFFFFF">'+
                        '<div class="cancelIcon"></div>'
              }
          oriStr = oriStr +  '    </td>'+
              '    <td bgcolor="#FFFFFF" align="center">'+saleDate+
              '    </td>'+
              '    <td bgcolor="#FFFFFF" align="center">'+saleNo+'</td>'+
              '    <td align="center" bgcolor="#FFFFFF">'+ replaceHtmlTag(clientName) +'</td>'+
              '    <td align="left" bgcolor="#FFFFFF">'+ replaceHtmlTag(productName) +'</td>'
              oriStr = oriStr + '    <td align="center" bgcolor="#FFFFFF" naem="IsOpenSaleTaxRate_1">'+ afterTaxAmt +'</td>'
              oriStr = oriStr + '    <td align="center" bgcolor="#FFFFFF">'+ receAmt +'</td>'+
              '    <td align="center" bgcolor="#FFFFFF">'+ replaceHtmlTag(accountSimpleName) +'</td>'+
              '    <td align="center" bgcolor="#FFFFFF">'+ replaceHtmlTag(warehouseName) +'</td>'+
              '    <td align="center" bgcolor="#FFFFFF">'+
                            '<a class="operate check" onclick="SelectSale(\''+ saleId +"','"+ saleNo +"','"+ clientName +"','"+ clientId +"','"+ warehouseSimpleName +"','"+ warehouseId +"','"+ otherFee +"','"+ accountId +'\')" title="选择"></a>';

         oriStr = oriStr + '</td></tr>'
        return oriStr;
    }

    function SelectSale(saleId, saleNo, clientName, clientId,warehouseSimpleName,warehouseId,otherFee,accountId) {
        var reqJson = {};
        reqJson["ClientId"] = clientId;
        reqJson["SaleId"] = saleId;
        reqJson["AccountId"] = accountId;
        reqJson["WareHouseId"] = warehouseId;
        reqJson["OtherFee"] = otherFee;

        parent.$('#openFrameDiv').dialog('close');
        var result = parent.sale_bi.getProductsBySaleId(JSON.stringify(saleId));
        var resultList = eval("(" + result + ")");
        var data = resultList["EachData"];
        if(data != null || data != ""){
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$("#spanSelectSale").hide();
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$("#spanReturnBody").show();
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$(".left").show();
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$("#SaleNo").val(saleNo);
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$("#SaleId").val(saleId);
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$("#spanClient").text(clientName);
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$("#ClientIds").val(clientId);
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$("#spanSaleNo").text(saleNo);
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$("#spanWare").text(warehouseSimpleName);
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$("#WarehouseId").val(warehouseId);
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.$("#OtherFee").val(getSystemDecimal(Number(otherFee)));
            parent.$("#tabs .panel:visible iframe")[0].contentWindow.AddSaleProduct(data,reqJson);
        }else{
            Dialog.alert("属性值加载失败");
        }

    }
</script>
